package com.car.web.controller.index;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.car.dal.dao.ndzjypb.NdzjypbDao;
import com.car.dal.dao.ndzjypb.NdzwpjDao;
import com.car.dal.object.Blkphone;
import com.car.dal.object.TgDepartment;
import com.car.dal.object.TgNdzjypb;
import com.car.dal.object.TgNdzwpj;
import com.car.dal.object.TgOffice;
import com.car.dal.object.TgUser;
import com.car.dal.object.TgUserinfo;
import com.car.dal.object.TgWork;
import com.car.service.ndzjypb.Ndzjypbservice;
import com.car.service.ndzjypb.Ndzwpjservice;
import com.car.util.JsonExecutor;
import com.car.util.Page;
import com.car.util.PageUtil;
import com.car.util.Result;
import com.car.util.ResultSupport;
import com.car.util.UserUtil;
import com.car.util.WebExecutor;
import com.car.util.JsonExecutor.JsonBiz;
import com.car.util.WebExecutor.Biz;
import com.car.web.controller.base.BaseController;
import com.car.web.controller.base.BaseVo;


/**
 * 竞思年度总结与评比
 * 此调查致力于企业和员工未来发展，请您发表自己真实的看法和意见，完成满意度调查问卷表及评比。
 * @author Administrator
 * 
 */
@Controller
@RequestMapping("/index")
public class NdzjypbController extends BaseController{

	private static final Logger logger = Logger.getLogger(UserController.class);
	@Resource
    private Ndzjypbservice ndzjypbservice;
	@Resource
	private NdzjypbDao ndzjypbDao;
	@Resource
    private Ndzwpjservice ndzwpjservice;
	@Resource
	private NdzwpjDao ndzwpjDao;
	
	
	// 添加竞思年度总结与评比  
	@RequestMapping(value = "/addndzjypb")
	public ModelAndView addndzjypb(ModelMap modelMap, final BaseVo vo, final HttpServletRequest request,
			final HttpServletResponse response) throws Exception {
		modelMap = WebExecutor.execute(logger, vo, new Biz() {
			public Result process() {
				Result result = new ResultSupport(true);
				TgUser user = UserUtil.getUserFromCookies();
				result.setDefaultModel("user", user);
				return result;
			}
		});
		return new ModelAndView("ndzjypb/add_ndzjypb", modelMap);
	}
	
	//保存竞思年度总结与评比
    @RequestMapping(value = "/save_ndzjypbs")
   	public ModelAndView save_ndzjypb(ModelMap modelMap, final BaseVo vo,
   			final HttpServletRequest request, final HttpServletResponse response)
   			throws Exception {
    	modelMap = JsonExecutor.execute(logger, vo, new JsonBiz() {
   			public Result process() {
   				Result result = new ResultSupport(true);
   				
   				TgNdzjypb ndzjypb = new TgNdzjypb();
   				ndzjypb.setAdd_username(request.getParameter("add_username"));
   				ndzjypb.setCenter(request.getParameter("center"));
   				if(ndzjypbDao.countEqual(ndzjypb) > 0){
   					result.setDefaultModel("msg", "2");
   					return result;
   				}
   				ndzjypb.setDepartment(request.getParameter("department"));
   				ndzjypb.setPost(request.getParameter("post"));
   				ndzjypb.setWorking_life(request.getParameter("working_life"));
   				ndzjypb.setA(Integer.valueOf(request.getParameter("a")));
   				ndzjypb.setB(Integer.valueOf(request.getParameter("b")));
   				ndzjypb.setC(Integer.valueOf(request.getParameter("c")));
   				ndzjypb.setD(Integer.valueOf(request.getParameter("d")));
   				ndzjypb.setE(Integer.valueOf(request.getParameter("e")));
   				ndzjypb.setF(Integer.valueOf(request.getParameter("f")));
   				ndzjypb.setG(Integer.valueOf(request.getParameter("g")));
   				ndzjypb.setH(Integer.valueOf(request.getParameter("h")));
   				ndzjypb.setI(Integer.valueOf(request.getParameter("i")));
   				ndzjypb.setJ(Integer.valueOf(request.getParameter("j")));
   				ndzjypb.setK(Integer.valueOf(request.getParameter("k")));
   				ndzjypb.setL(Integer.valueOf(request.getParameter("l")));
   				ndzjypb.setM(Integer.valueOf(request.getParameter("m")));
   				ndzjypb.setN(Integer.valueOf(request.getParameter("n")));
   				ndzjypb.setO(Integer.valueOf(request.getParameter("o")));
   				ndzjypb.setP(Integer.valueOf(request.getParameter("p")));
   				ndzjypb.setQ(Integer.valueOf(request.getParameter("q")));
   				ndzjypb.setR(Integer.valueOf(request.getParameter("r")));
   				ndzjypb.setS(Integer.valueOf(request.getParameter("s")));
   				ndzjypb.setT(Integer.valueOf(request.getParameter("t")));
   				ndzjypb.setU(Integer.valueOf(request.getParameter("u")));
   				ndzjypb.setV(Integer.valueOf(request.getParameter("v")));
   				ndzjypb.setW(Integer.valueOf(request.getParameter("w")));
   				ndzjypb.setX(Integer.valueOf(request.getParameter("x")));
   				ndzjypb.setY(Integer.valueOf(request.getParameter("y")));
   				ndzjypb.setZ(Integer.valueOf(request.getParameter("z")));
   				ndzjypb.setA1(Integer.valueOf(request.getParameter("a1")));
   				ndzjypb.setB1(Integer.valueOf(request.getParameter("b1")));
   				ndzjypb.setC1(Integer.valueOf(request.getParameter("c1")));
   				ndzjypb.setD1(Integer.valueOf(request.getParameter("d1")));
   				ndzjypb.setE1(Integer.valueOf(request.getParameter("e1")));
   				ndzjypb.setF1(Integer.valueOf(request.getParameter("f1")));
   				ndzjypb.setG1(Integer.valueOf(request.getParameter("g1")));
   				ndzjypb.setH1(Integer.valueOf(request.getParameter("h1")));
   				ndzjypb.setI1(Integer.valueOf(request.getParameter("i1")));
   				ndzjypb.setJ1(Integer.valueOf(request.getParameter("j1")));
   				ndzjypb.setK1(Integer.valueOf(request.getParameter("k1")));
   				ndzjypb.setL1(Integer.valueOf(request.getParameter("l1")));
   				ndzjypb.setM1(Integer.valueOf(request.getParameter("m1")));
   				ndzjypb.setN1(Integer.valueOf(request.getParameter("n1")));
   				ndzjypb.setO1(Integer.valueOf(request.getParameter("o1")));
   				ndzjypb.setP1(request.getParameter("p1"));
   				ndzjypb.setCreat_time(new Date());
   				
   				ndzjypbservice.insert(ndzjypb);
				result.setDefaultModel("msg", "1");
   				return result;
   			}
   		});
   		return new ModelAndView("", modelMap);
   	}
	
    //查看竞思年度总结与评比
    @RequestMapping(value = "/ndzjypb")
	public ModelAndView ndzjypb(ModelMap modelMap, final BaseVo vo, final HttpServletRequest request,
			final HttpServletResponse response) throws Exception {
		modelMap = WebExecutor.execute(logger, vo, new Biz() {
			public Result process() {
				Result result = new ResultSupport(true);
				TgUser user = UserUtil.getUserFromCookies();
				TgNdzjypb ndzjypb = new TgNdzjypb();
				if(user.getUsername().equals("system")){
					Integer currPage = vo.getCurrPage() == null ? 1 : vo.getCurrPage();
					Integer total = ndzjypbservice.getNdzjypbCount(ndzjypb);
					Page page = PageUtil.createPage(20, currPage, total);
					List<TgNdzjypb> list =ndzjypbservice.getNdzjypbliet(ndzjypb,page);
					result.setDefaultModel("list", list);
					result.setDefaultModel("page", page);
				}else{
					ndzjypb.setAdd_username(user.getNickname());
					Integer currPage = vo.getCurrPage() == null ? 1 : vo.getCurrPage();
					Integer total = ndzjypbservice.getNdzjypbCount(ndzjypb);
					Page page = PageUtil.createPage(20, currPage, total);
					List<TgNdzjypb> list =ndzjypbservice.getNdzjypbliet(ndzjypb,page);
					result.setDefaultModel("list", list);
				}
				result.setDefaultModel("user", user);
				return result;
			}
		});
		return new ModelAndView("ndzjypb/ndzjypbList", modelMap);
	}
    
 // 添加竞思年度总结与评比  
 	@RequestMapping(value = "/addndzwpj")
 	public ModelAndView addndzwpj(ModelMap modelMap, final BaseVo vo, final HttpServletRequest request,
 			final HttpServletResponse response) throws Exception {
 		modelMap = WebExecutor.execute(logger, vo, new Biz() {
 			public Result process() {
 				Result result = new ResultSupport(true);
 				TgUser user = UserUtil.getUserFromCookies();
 				result.setDefaultModel("user", user);
 				return result;
 			}
 		});
 		return new ModelAndView("ndzjypb/add_ndzwpj", modelMap);
 	}
    
 	//保存竞思年度总结与评比
    @RequestMapping(value = "/save_ndzwpj")
   	public ModelAndView save_ndzwpj(ModelMap modelMap, final BaseVo vo,
   			final HttpServletRequest request, final HttpServletResponse response)
   			throws Exception {
    	modelMap = JsonExecutor.execute(logger, vo, new JsonBiz() {
   			public Result process() {
   				Result result = new ResultSupport(true);
   				
   				TgNdzwpj tgNdzwpj = new TgNdzwpj();
   				tgNdzwpj.setAdd_username(request.getParameter("add_username"));
   				tgNdzwpj.setCenter(request.getParameter("center"));
   				tgNdzwpj.setPj_name(request.getParameter("pj_name"));
   				if(ndzwpjDao.countEqual(tgNdzwpj) > 0){
   					result.setDefaultModel("msg", "2");
   					return result;
   				}
   				tgNdzwpj.setA(request.getParameter("a"));tgNdzwpj.setB(request.getParameter("b"));
   				tgNdzwpj.setC(request.getParameter("c"));tgNdzwpj.setD(request.getParameter("d"));
   				tgNdzwpj.setE(request.getParameter("e"));tgNdzwpj.setF(request.getParameter("f"));
   				tgNdzwpj.setG(request.getParameter("g"));tgNdzwpj.setH(request.getParameter("h"));
   				tgNdzwpj.setI(request.getParameter("i"));tgNdzwpj.setJ(request.getParameter("j"));
   				tgNdzwpj.setK(request.getParameter("k"));tgNdzwpj.setL(request.getParameter("l"));
   				tgNdzwpj.setM(request.getParameter("m"));tgNdzwpj.setN(request.getParameter("n"));
   				tgNdzwpj.setO(request.getParameter("o"));tgNdzwpj.setP(request.getParameter("p"));
   				tgNdzwpj.setQ(request.getParameter("q"));tgNdzwpj.setR(request.getParameter("r"));
   				tgNdzwpj.setS(request.getParameter("s"));tgNdzwpj.setT(request.getParameter("t"));
   				tgNdzwpj.setCreate_time(new Date());
   				ndzwpjservice.insert(tgNdzwpj);
				result.setDefaultModel("msg", "1");
   				return result;
   			}
   		});
   		return new ModelAndView("", modelMap);
   	}
 	
 	
	
}
